<?php 
/* P3(c)

******************************************************************************
                                                                                      
                         __                                                        
                        /__)                                                       
                       /__        P3 - moving Technologie            
                        __)                                                          
                        __)                                                          
                                                                                        
                                                                                        
       Copyright 2009 by p3.co.at                                                                                 
                                                                                        
       visit www.p3.co.at to get more Informations 
       about Teriko - Betriebsdatenerfassung                                                                                 
       - it's not allowed to change this scripts
       - it's not allowed to remove this copyright-tag

       -- you can download the complete license   
          under http://www.teriko.org

 (c) by Patrik Pfaffenbauer and P3 (http://www.p3.co.at)

 | Programname: P3.Teriko
 | Authtor: P3.Verein
 | Coder: Patrik Pfaffenbauer
 | Version: 0.1

 | Change Index
 |_____________________________________________
 |                                             |
 |4.3.2010 Erstellung | Patrik Pfaffenbauer    |
 |_____________________________________________|

******************************************************************************

P3(c) */ 

class DataGridView
{
	var $headerCount = 0;
	var $rowCount = 0;
	var $valueCount = 0;
	var $filterValue;
	var $site;
	var $owner;
	
	var $deleteButton = true;
	var $editButton = true;
	
	var $object;
	var $object_id;
	
	public function DataGridView($owner)
	{
		if(!$owner->permission->editPermission)
		{
			$this->editButton = false;
		}
		if(!$owner->permission->deletePermission)
		{
			$this->deleteButton = false;
		}
		
		$this->owner = $owner;
		$this->site = $_GET['s'];
		
		echo '<input type="hidden" id="dgv-site" name="dgv-site" value="'.$_GET['s'].'" />';
		echo '<form action="index.php?s='.$_GET['s'].'" method="post" name="adminForm">';
	}
	
	public function AddComboBoxFilter($dataSource, $filterName, $filterValue, $filterID)
	{
		echo '
			<table>
				<tr>
					<td width="100%">
					'.$filterName.'
					<select name="search" onChange="Submitform(\'search\')">';
		
		while($line = $GLOBALS['db']->Fetch($dataSource))
		{
			if($filterValue == $line->id)
				echo '<option value="'.$line->id.'" selected>'.$line->value.'</option>';
			else
				echo '<option value="'.$line->id.'">'.$line->value.'</option>';
		}
		echo '</select>
		<input type="hidden" name="filterID" value="'.$filterID.'" />';
		
		if($filterValue != "")
		{
			echo '<button onclick="Submitform(\'paint\');">'.$GLOBALS['lang']->GetLanguage("Common", "restore").'</button>';
		}
		
		echo '</td></tr></table>';
	}
	
	public function AddTextFilter($filterValue)
	{
		echo '<table>
				<tr>
					<td width="100%">
						Filter:
						<input type="text" name="search" id="search" value="'.$filterValue.'" class="text_area" />
						<button onclick="Submitform(\'search\');">'.$GLOBALS['lang']->GetLanguage("Common", "search").'</button>';
		
		if($filterValue != "")
		{
			echo '<button onclick="Submitform(\'paint\');">'.$GLOBALS['lang']->GetLanguage("Common", "restore").'</button>';
		}
		
		
		echo '</td>
				</tr>
			</table>
		';
	}
	
	public function OpenHeader()
	{
		echo '
			<table class="adminlist">
				<thead>
					<tr>';
			
		$this->AddHeader("#", "20", false);
		$this->AddHeader("", "20", false);
	}

	public function AddHeader($name, $width, $title)
	{
		if($title)
		{
			echo '
			<th class="title" nowrap="nowrap" width="'.$width.'">
				'.$name.'
			</th>';
		}
		else
		{
			echo '<th width="'.$width.'">
				'.$name.'
			</th>';
		}
		
		$this->headerCount++;
	}
	public function CloseHeader()
	{
		if($this->editButton)
			$this->AddHeader($GLOBALS['lang']->GetLanguage("Common", "edit"), "10%", "edit");
			
		if($this->deleteButton)
			$this->AddHeader($GLOBALS['lang']->GetLanguage("Common", "delete"), "10%", "delete");
			
		echo '</tr>
			</thead>
			<tbody>';
	}
	
	public function AddRow($id)
	{
		echo '<tr class="row'.$this->rowCount.'" id="row'.$this->rowCount.'">
		<td class="title" nowrap="nowrap" width="20" align="center">
				'.($this->rowCount+1).'			</td>

			<td align="center" width="20">
				<input type="radio" id="cb'.$this->rowCount.'" name="id" value="'.($id).'" onclick="IsChecked(this.checked);" />
			</td>
		';
		$this->rowCount++;
	}
	public function AddData($value, $title, $link, $fieldName)
	{
		if($fieldName == "")
		{
			echo '<td> </td>';
			return;
		}

			
		if($title == "editlink")
		{
			echo '<td>
			<span class="editlinktip hasTip" title="'.htmlentities($title).'">
				<a href="'.$link.'">
					'.$value.'</a></span>
			</td>';
		}
		else if($title == "bool-fastEdit")
		{
			if($value)
			{
				echo '<td align="center">
						<a href="javascript:void(0);" onclick="return ListItemTask(\'cb'.($this->rowCount-1).'\',\'activate\');">
							<img src="images/tick.png" border="0" alt="gesperrt" /></a>
					</td>';
			}
			else
			{
				echo '<td align="center">
						<a href="javascript:void(0);" onclick="return ListItemTask(\'cb'.($this->rowCount-1).'\',\'activate\');">
							<img src="images/publish_x.png" border="0" alt="gesperrt" /></a>
					</td>';
			}
		}
		else if($title == "bool")
		{
			if($value)
			{
				echo '<td align="center">
							<img src="images/tick.png" border="0" alt="gesperrt" />
					</td>';
			}
			else
			{
				echo '<td align="center">
							<img src="images/publish_x.png" border="0" alt="gesperrt" />
					</td>';
			}
		}
		else if($title == "fastEdit")
		{
			if($value == "")
				$value = "-";
				
			echo '<td align="center">
				<input type="hidden" id="v-'.$this->rowCount.'-'.$this->valueCount.'" name="v-'.$this->rowCount.'-'.$this->valueCount.'" value="'.$fieldName.'"/>
				<div id="div-'.$this->rowCount.'-'.$this->valueCount.'"><a href="javascript::void(0);" id="a-'.$this->rowCount.'-'.$this->valueCount.'" onmouseover="return overlib(\''.$GLOBALS['lang']->GetLanguage("Common", "fastEdit").'\');" onmouseout="return nd();" onclick="SwitchTextToEdit(\''.$this->rowCount.'-'.$this->valueCount.'\');return nd();">'.$value.'</a></div></td>';
		}
		else if($title == "comboBox-edit")
		{
			if($value == "")
				$value = "-";
			
			$array = "";
			for($i = 0; $i < count($this->object); $i++)
			{
				$array .= implode(',', $this->object[$i]).";";
			}
				
			echo '<td align="center">
				<input type="hidden" id="id-'.$this->rowCount.'-'.$this->valueCount.'" name="id-'.$this->rowCount.'-'.$this->valueCount.'" value="'.$this->object_id.'" />
				<input type="hidden" id="v-'.$this->rowCount.'-'.$this->valueCount.'" name="v-'.$this->rowCount.'-'.$this->valueCount.'" value="'.$fieldName.'"/>
				<div id="div-'.$this->rowCount.'-'.$this->valueCount.'"><a href="javascript::void(0);" id="a-'.$this->rowCount.'-'.$this->valueCount.'" onmouseover="return overlib(\''.$GLOBALS['lang']->GetLanguage("Common", "fastEdit").'\');" onmouseout="return nd();" onclick="SwitchToComboBoxEdit(\''.$array.'\', \''.$this->rowCount.'-'.$this->valueCount.'\');return nd();">'.$value.'</a></div></td>';
		}
		else
		{
			echo '<td align="center">'.$value.'</td>';
		}
		
		$this->valueCount++;
	}
	public function AddHidden($name, $value)
	{
		echo '
		<input type="hidden" name="'.$name.'" value="'.$value.'" />';
	}
	
	public function CloseRow()
	{
		
		if($this->editButton)
		{
			echo '<td align="center">
							<a href="javascript:void(0);" onclick="return ListItemTask(\'cb'.($this->rowCount-1).'\',\'edit\');">
								<img src="images/edit.png" border="0" height="15px" width="15px" alt="edit" 
								onmouseover="return overlib(\''.$GLOBALS['lang']->GetLanguage("Common", "editRow").'\');" onmouseout="return nd();"/></a>
					</td>';
		}
		if($this->deleteButton)
		{
			echo '<td align="center">
					<a href="javascript:void(0);" onclick="return OnConfirmListItemTask(\'cb'.($this->rowCount-1).'\',\'delete\');">
						<img src="images/delete.png" border="0" height="15px" width="15px" alt="edit" 
						onmouseover="return overlib(\''.$GLOBALS['lang']->GetLanguage("Common", "deleteRow").'\');" onmouseout="return nd();"/></a>
					</td>';
		}
		echo '</tr>';
	}
	public function CloseDataGrid()
	{
		echo '
		<input type="hidden" name="item" value="" />
		<input type="hidden" name="action" value="" />
		<input type="hidden" name="boxchecked" value="0" />
		</tbody></table></form>';
	}
	
	public function AddMisc($href, $onclick, $text)
	{
		if($href == "")
			$href = "#";
			
		echo '<td align="center">
						<a href="'.$href.'" onclick="'.$onclick.'">'.$text.'</a>
					</td>';
	}
}

?>